home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
c80tcog.lbr
/
QSORT.C
< prev
next >
Wrap
Text File
|
1985-08-09
|
896b
|
37 lines
/*
Contributed by Les Johnson, 12/21/82
This is the qsort routine, utilizing the
shell sort technique given in the Software
Tools book (by Kernighan & Plauger).
For C/80 from The Software Toolworks.
*/
qsort(base, nel, width, compar)
char *base; int (*compar)();
unsigned width,nel;
{ int i, j;
unsigned gap, ngap, t1;
int jd, t2;
t1 = nel * width;
for (ngap = nel / 2; ngap > 0; ngap /= 2) {
gap = ngap * width;
t2 = gap + width;
jd = base + gap;
for (i = t2; i <= t1; i += width)
for (j = i - t2; j >= 0; j -= gap) {
if ((*compar)(base+j, jd+j) <=0) break;
_swp(width, base+j, jd+j);
}
}
}
_swp(w,a,b) /* swap, used by qsort */
char *a,*b;
unsigned w;
{
char tmp;
while(w--) {tmp = *a; *a++ = *b; *b++ = tmp;}
}